import request from '@/utils/request'

// 获取员工列表
export const getEmployeeListAPI = (query) => {
  return request({
    method: 'get',
    url: '/sys/user',
    params: query
  })
}

/**
 * 删除员工
 * @param {String} id
 * @returns Promise
 */
export const delEmployeeAPI = (id) => {
  return request({
    method: 'delete',
    url: `/sys/user/${id}`
  })
}

// 新增员工
export const addEmployeeAPI = (form) => {
  return request({
    method: 'post',
    url: '/sys/user',
    data: form
  })
}

// 批量导入员工
export const addEmployeeBatchAPI = (list) => {
  return request({
    method: 'post',
    url: '/sys/user/batch',
    data: list
  })
}

// 获取员工信息
export const getEmployeeInfoAPI = (id) => {
  return request({
    method: 'get',
    url: `/sys/user/${id}`
  })
}

// 更新员工信息
export const editEmployeeAPI = (data) => {
  return request({
    method: 'put',
    url: `/sys/user/${data.id}`,
    data
  })
}

/**
 * 给员工分配角色
 * @param {String} id
 * @param {Array} roleIds
 * @returns Promise
 */
export const assignRoleAPI = (id, roleIds) => {
  return request({
    method: 'put',
    url: '/sys/user/assignRoles',
    data: {
      id,
      roleIds
    }
  })
}
